package ntd.tool.abnormal;

import cn.hutool.core.text.StrFormatter;
import cn.hutool.log.StaticLog;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ComAbnormal extends RuntimeException {

    public Integer code = 500;

    public ComAbnormal(String message) {
        super(message);
    }

    public ComAbnormal(int code, String message) {
        super(message);
        setCode(code);
    }

    public ComAbnormal(String message, Object ... args) {
        super(StrFormatter.format(message, args));
        StaticLog.error(StrFormatter.format(message, args));
    }

    /**
     * 抛出自身异常，控制太打印并且转换为运行时异常抛出
     */
    public void throwNew() {
        this.printStackTrace();
        StaticLog.error("错误日志信息[{}]......", this.getMessage());
        throw this;
    }
}
